<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\UserCenter;
use Illuminate\Support\Facades\DB;

class UserCenterSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $dataAll=[];
        $snowflake = app('snowflake');
        $now = time();
        $mobile = 61450000000;
        for ($i=1; $i<=2000; $i++)
        {
            $mobile++;
            $data=[
                'user_id' => $snowflake->id(),
                'login_name' => \Str::random(8).$mobile,
                'password' => \Str::random(64), 
                'mobile' => $mobile,
                'email' => $mobile.'@email.com',
                'created_at'=>$now,
                'updated_at'=>$now,
            ];
            $dataAll[] = $data;
        }
        // DB::listen(function($query) {
        //     $bindings = $query->bindings;
        //     $sql = $query->sql;
        //     foreach ($bindings as $replace){
        //         $value = is_numeric($replace) ? $replace : "'".$replace."'";
        //         $sql = preg_replace('/\?/', $value, $sql, 1);
        //     }
        //     dd($sql);
        // });
       $db = DB::table('user_center');
       #存在内存泄漏
       $db->getConnection()->unsetEventDispatcher();
       $db->getConnection()->disableQueryLog();
       $db ->insert($dataAll);
       unset($dataAll);
       unset($db);
    }
}
